package com.example.demo.controller;

import com.example.demo.domain.Order;
import com.example.demo.feign.OrderServiceClient;
import com.example.demo.order.OrderService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * Created by fandg on 2020/3/31.
 */
@RestController
@RequestMapping("user")
public class UserController {

    public static final Logger logger = LoggerFactory.getLogger(UserController.class);

    @Autowired
    OrderServiceClient orderServiceClient;

    @RequestMapping("/list")
    public List<Order> userList() {
        logger.info("调用USER SERVICE的列表查询 ");
        List<Order> orders = orderServiceClient.orderList();
        return orders;
    }

    @RequestMapping("/one")
    public Order get(Long id) {
        logger.info("调用USER SERVICE的单个查询， id = {} ", id);
        /*String serviceUrl = "http://localhost:8001/order/one";
        Map<String ,Integer> map = new HashMap<>();
        map.put("id", id);
        ResponseEntity<Order> forEntity = restTemplate.getForEntity(serviceUrl, Order.class, map);*/
        return orderServiceClient.getOrder(id);
    }
}
